home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Complet / emovix / eMovix-0.9.0pre1_Setup.exe / {app} / src / movix / setHardware.pl < prev    next >
Encoding:
Perl Script  |  2003-12-25  |  3.1 KB  |  107 lines

  1. #!/usr/bin/perl
  2.  
  3. $modLog = "/tmp/modprobe.log";
  4. $modErr = "/tmp/modprobe.err";
  5.  
  6. #######################
  7. ### Loading rtc & agpgart modules...
  8. ######
  9. system "modprobe -s rtc     >> $modLog 2>> $modErr";
  10. system "modprobe -s apm     >> $modLog 2>> $modErr";
  11. system "modprobe -s agpgart >> $modLog 2>> $modErr";
  12.  
  13. # load the OSS emulation module for systems that don't work with alsa
  14. system "modprobe -s snd-pcm-oss >> $modLog 2>> $modErr";
  15.  
  16. system "modprobe -s supermount >> $modLog 2>> $modErr";
  17.  
  18. ########################################
  19. ### Collecting info on your CD/DVD drive(s)
  20. ### We need the CD/DVD devices in lexical order, so we first
  21. ### make a note of all IDE devices available...
  22. #############
  23. $ideDir = "/proc/ide/";
  24. my @ideCDROMs;
  25. opendir IDE, $ideDir;
  26. while (my $drive = readdir IDE) {
  27.   next unless $drive =~ /^hd\w$/;
  28.   my $media = `cat $ideDir$drive/media`;
  29.   chop $media;
  30.   push @ideCDROMs, $drive if $media eq "cdrom";
  31. }
  32. closedir(IDE);
  33. ##############
  34. ### and then we sort them
  35. #############
  36. my @sortedIDEcdroms = sort @ideCDROMs;
  37. for ( my $i=0; $i < @sortedIDEcdroms; $i++ ) {
  38.   my $model = `cat $ideDir$sortedIDEcdroms[$i]/model`;
  39.   system "ln -s /dev/cdroms/cdrom$i /dev/dvd" 
  40.     if !-e "/dev/dvd" and $model =~ /dvd/i;
  41.   push @cdDrives, $model;
  42. }
  43. ########################################
  44. ### Collecting info on your SCSI CD/DVD drive(s)
  45. ### should be ordered based on scsi id
  46. ### ATTENTION! this assumes that IDE drivers are
  47. ### always before SCSI drives in /dev/cdrom/cdroms[0-i]
  48. #############
  49. $scsiDir = "/proc/scsi/";
  50. my @scsiCDROMs;
  51. opendir SCSI, "$scsiDir";
  52. while (my $drive = readdir SCSI) {
  53.   next unless $drive =~ /^scsi$/;
  54.   my $model;
  55.   open CONFIG, "$scsiDir$drive";
  56.   while (<CONFIG>) {
  57.     if ( /.*Type:.*CD-ROM.*/ ){
  58.       push @scsiCDROMs, $model;
  59.       next;
  60.     }
  61.     if ( /.*Model: (.*)Rev.*/ ){
  62.       $model=$1;
  63.       next;
  64.     }
  65.   }
  66.   close CONFIG;
  67. }
  68. closedir SCSI;
  69. ##############
  70. ### now we sort them too
  71. #############
  72. my @sortedSCSIcdroms = sort @scsiCDROMs;
  73. ### Finally we use as default dvd player the first drive 
  74. ### whose model name matches 'dvd'
  75. for ( my $i=@ideCDROMs; $i < @sortedSCSIcdroms+@ideCDROMs; $i++ ) {
  76.   my $model = $sortedSCSIcdroms[$i-@ideCDROMs];
  77.   push @cdDrives, $model;
  78.   system "ln -s /dev/cdroms/cdrom$i /dev/dvd"
  79.     if $model =~ /dvd/i and  !-e "/dev/dvd";
  80. }
  81. ### let's make sure there's a /dev/dvd even though no such label has been found
  82. `ln -s /dev/cdroms/cdrom0 /dev/dvd` if !-e "/dev/dvd";
  83.  
  84. ### Now, in case there's more than a CD/DVD drive we need to modify the MPlayer menu
  85. ### in order to provide a "Create playlist" item for each drive
  86. if( @cdDrives > 1 ){
  87.   my $pls = "";
  88.   for ( my $i=0; $i < @cdDrives; $i++ ) {
  89.     $pls .= "\t<e name=\"" . truncateTo(20,$cdDrives[$i]) . "\" ok=\"loadcd $i\"/>\n";
  90.   }
  91.   $menu = `cat /root/.mplayer/menu.conf`;
  92.   $menu =~ s/Play CD\" ok=\"loadcd 0/Play CD ...\" ok=\"set_menu drives/;
  93.   $menu .= "\n\n<cmdlist name=\"drives\" title=\"CD/DVD Drives\" ptr=\"<>\" >\n";
  94.   $menu .= $pls;
  95.   $menu .= "</cmdlist>\n";
  96.   open MENU, "> /root/.mplayer/menu.conf";
  97.   print MENU $menu;
  98.   close MENU;
  99. }
  100.  
  101. sub truncateTo {
  102.   my $n      = shift;
  103.   my $string = shift;
  104.   $string =~ /^(.{1,$n})/;
  105.   return $1;
  106. }
  107.